package regex;
/**
 * String[] split(String regex)
 *           根据给定正则表达式的匹配拆分此字符串
 */
public class RegexDemo09 {
    public static void main(String[] args) {
        method01();  // 切割 字符串
        method02();  // 切割ip
    }

    private static void method02() {
        String ipStr = "192.168.1.132";                  //  192
        String[] splitIp = ipStr.split("\\.");   // 168
        for (int i = 0; i < splitIp.length; i++) {      // 1
            System.out.println(splitIp[i]);             //  132
        }
    }

    private static void method01() {
        String str = "I   Love   java  so  much";            //   I
        String regexs = " +";  // 匹配一个或者多个空格        //    Love
        String[] splitStr = str.split(regexs);             //    java
        for (int i = 0; i < splitStr.length; i++) {         //   so
            System.out.println(splitStr[i]);                //   much
        }
    }
}
